home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: clientReceive.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:54 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "link.h"
- #include "host.h"
- #include "bitvec.h"
- #include "msgvector.h"
- #include "msg_funcs.h"
- #include "util_funcs.h"
- #include "thread_funcs.h"
- #include "thread_globals.h"
- #include "msg_globals.h"
-
-
- extern int errno;
-
- void
- clientReceive (
-
- register LINK *link
- )
- {
-
- register MESSAGE *message;
- register MSGVECTOR *msgVector;
- register TCB *tcb;
-
-
- TRPRINT(TR_MSG, TR_LEVEL_1, ("got message on link:%d", link->id));
-
- /*
- * check to see if there is a waiter on that link
- */
- if ((tcb = (TCB *) listDeq( &(link->tcbList) )) != NULL) {
-
- TRPRINT(TR_MSG, TR_LEVEL_2, ("have waiting task:%d", tcb->id));
-
- /*
- * switch to that thread and restart the Active thread
- */
- freeThread(Active);
- threadSwitch(tcb);
- threadRestart();
- }
-
- /*
- * get a register pointer to the message buffer
- */
- message = &(Active->message);
-
- /*
- * Read the message.
- * Since the client could be sending us a MESSAGE that is
- * smaller than our idea of a MESSAGE (e.g. a message of a
- * different protocol version), we must NOT block trying
- * to read a full MESSAGE.
- *
- * Thus, if we get a short read, we must check the PROTOCOL_VERSION
- * before we go on to read the rest of the MESSAGE.
- * It is sufficient to check only the very first PROTOCOL_VERSION
- * separately, because TCP guarantees that we will not get
- * messages from sources other than the client peer.
- */
- if( link->flags == LINK_ACCEPT ) {
- if (receive(link, (char *) message,
- sizeof(message->header.version)) < 0){
- TRPRINT(TR_MSG, TR_LEVEL_2, ("receive failed:%d", errno));
- threadRestart();
- }
- if (message->header.version != MESSAGE_VERSION) {
- SM_ERROR(TYPE_USER, esmPROTOCOLVERSION);
- reply(esmFAILURE, Active->errno, 1, TRUE);
- /* hope that the client shuts the cx */
- }
-
- if (receive(link, ((char *) message)+ sizeof(message->header.version),
- (sizeof(MESSAGE)-sizeof(message->header.version))) < 0) {
- TRPRINT(TR_MSG, TR_LEVEL_2, ("receive failed:%d", errno));
- threadRestart();
- }
-
- link->flags = LINK_RECV;
- } else {
- /*
- * we already know that are speaking the same protocol
- * so do not bother to check the version in a separate
- * read request.
- */
- if (receive(link, (char *) message, sizeof(MESSAGE)) < 0) {
- TRPRINT(TR_MSG, TR_LEVEL_2, ("receive failed:%d", errno));
- threadRestart();
- }
- /*
- * Check to see if the message magic is valid
- * At this point, the MESSAGE_VERSION is acting
- * as a magic number. This will catch such surprises
- * as a client having a longer appended part (from the previous
- * message) than we expected, resulting in our reading
- * what we think should be a MESSAGE, but is in fact the
- * rest of the previous (appended part of the) message.
- */
- if (message->header.version != MESSAGE_VERSION) {
-
- SM_ERROR(TYPE_USER, esmBADMESSAGEMAGIC);
- reply(esmFAILURE, Active->errno, 1, TRUE);
- /* hope that the client shuts the cx */
- }
- }
-
- TRPRINT(TR_MSG, TR_LEVEL_2, ("got message of type:%d",
- message->header.type));
-
- /*
- * save the link that the request came in on
- */
- Active->linkId = link->id;
-
- if( !(message->header.replyRequested) )
- MsgStats.no_reply_requested[message->header.type]++;
- MsgStats.received [message->header.type]++;
-
-
- /*
- * check to see if the message header type is correct
- */
- if (message->header.type > MAX_MSG_NUMBER) {
-
- /*
- * send error back to user
- */
- SM_ERROR(TYPE_USER, esmBADMESSAGENUMBER);
- reply(esmFAILURE, Active->errno, 1, TRUE);
- }
-
- /*
- * get a pointer to the message function table
- */
- msgVector = &(MsgVectorTable[message->header.type]);
- SM_ASSERT(LEVEL_1, (msgVector->msgtype == message->header.type));
-
- /*
- * check to see that the class is appropriate
- */
- if (msgVector->linkClass != link->linkClass) {
-
- TRPRINT(TR_MSG, TR_LEVEL_2, ("bad link class: message type %d",
- message->header.type));
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- /*
- * call the function
- */
- (*(msgVector->function))(message, link);
-
- /* ok to get here now. Return to main loop */
- }
-